/*************************************************************************
	> File Name: 8.368C.cpp
	> Author: hug
	> Mail: hug@haizeix.com
	> Created Time: 二  2/11 21:39:56 2025
 ************************************************************************/

#include <iostream>
using namespace std;

#define int long long

int T(int x) {
    return (x - x / 3) + x / 3 * 3;
}

int n;
int ans = 0;

int erfen(int t, int h) {
    int l = 0, r = h + 1, mid;
    while (l < r) {
        mid = (l + r) / 2;
        if (T(t + mid) - T(t) < h) l = mid + 1;
        else r = mid;
    }
    return l;
}

int32_t main() {
    cin >> n;
    for (int i = 1, h; i <= n; i++) {
        cin >> h;
        ans += erfen(ans, h);
    }
    cout << ans << endl;
    return 0;
}
